<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next-haha.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next-haha.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next-haha.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/all.min.css" integrity="sha256-VHqXKFhhMxcpubYf9xiWdCiojEbY9NexQ4jh8AxbvcM=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"ming.theyan.gs","root":"/","images":"/images","scheme":"Pisces","darkmode":false,"version":"8.25.0","exturl":false,"sidebar":{"position":"left","width_expanded":320,"width_dual_column":240,"display":"post","padding":18,"offset":12},"hljswrap":true,"codeblock":{"theme":{"light":"default","dark":"stackoverflow-dark"},"prism":{"light":"prism","dark":"prism-dark"},"copy_button":{"enable":false,"style":null},"fold":{"enable":false,"height":500},"language":false},"bookmark":{"enable":true,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"duration":200,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"top_n_per_article":1,"unescape":false,"preload":false,"trigger":"auto"}}</script><script src="/js/config.js" defer></script>

    <meta name="description" content="缘起业界良心的谷歌云（gcp）让我给玩儿坏了呀，原本这一期还没结束（应该到年底），可我的 300 刀的免费额度一个月前就已经花光了，于是乎，我的服务被停掉了。数据都没能机会拉取下来。 这样的话，给我自己折腾了进二十年的博客一个新的归宿又马上变成了火烧眉毛的事情了，早先其实一直在关注 GitHub Actions，而且也早就有申请，所以就乘着这个机会，把博客源文件、网站（静态内容）全都放在 GitH">
<meta property="og:type" content="article">
<meta property="og:title" content="How to auto deploy Hexo site to GitHub pages via Github Actions">
<meta property="og:url" content="https://ming.theyan.gs/2019/10/hexo-github_action-github_pages/index.html">
<meta property="og:site_name" content="运维烂笔头">
<meta property="og:description" content="缘起业界良心的谷歌云（gcp）让我给玩儿坏了呀，原本这一期还没结束（应该到年底），可我的 300 刀的免费额度一个月前就已经花光了，于是乎，我的服务被停掉了。数据都没能机会拉取下来。 这样的话，给我自己折腾了进二十年的博客一个新的归宿又马上变成了火烧眉毛的事情了，早先其实一直在关注 GitHub Actions，而且也早就有申请，所以就乘着这个机会，把博客源文件、网站（静态内容）全都放在 GitH">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-10-02T02:41:12.000Z">
<meta property="article:modified_time" content="2019-10-03T10:43:35.000Z">
<meta property="article:author" content="老杨">
<meta property="article:tag" content="Hexo">
<meta property="article:tag" content="GitHub Actions">
<meta property="article:tag" content="GitHub Pages">
<meta property="article:tag" content="nodejs">
<meta property="article:tag" content="blog">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://ming.theyan.gs/2019/10/hexo-github_action-github_pages/">


<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://ming.theyan.gs/2019/10/hexo-github_action-github_pages/index.html","path":"2019/10/hexo-github_action-github_pages/index.html","title":"How to auto deploy Hexo site to GitHub pages via Github Actions"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>How to auto deploy Hexo site to GitHub pages via Github Actions | 运维烂笔头</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-106574959-2"></script>
  <script class="next-config" data-name="google_analytics" type="application/json">{"tracking_id":"UA-106574959-2","only_pageview":false,"measure_protocol_api_secret":null}</script>
  <script src="/js/third-party/analytics/google-analytics.js" defer></script>

  <script src="/js/third-party/analytics/baidu-analytics.js" defer></script>
  <script async src="https://hm.baidu.com/hm.js?fdef9ded31bdb8b2dab08eddebdd5fed"></script>







  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous" defer></script>
<script src="/js/utils.js" defer></script><script src="/js/motion.js" defer></script><script src="/js/sidebar.js" defer></script><script src="/js/next-boot.js" defer></script><script src="/js/bookmark.js" defer></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.5.0/search.js" integrity="sha256-xFC6PJ82SL9b3WkGjFavNiA9gm5z6UBxWPiu4CYjptg=" crossorigin="anonymous" defer></script>
<script src="/js/third-party/search/local-search.js" defer></script>







  




<!-- google adsense -->
<script data-ad-client="ca-pub-1045025618858716" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="运维烂笔头" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">运维烂笔头</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">一个 SA 老兵的工作日志</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-projects"><a href="/projects" rel="section"><i class="fa fa-code fa-fw"></i>projects</a></li><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a></li><li class="menu-item menu-item-commonweal"><a href="/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
      <div class="search-header">
        <span class="search-icon">
          <i class="fa fa-search"></i>
        </span>
        <div class="search-input-container">
          <input autocomplete="off" autocapitalize="off" maxlength="80"
                placeholder="搜索..." spellcheck="false"
                type="search" class="search-input">
        </div>
        <span class="popup-btn-close" role="button">
          <i class="fa fa-times-circle"></i>
        </span>
      </div>
      <div class="search-result-container">
        <div class="search-result-icon">
          <i class="fa fa-spinner fa-pulse fa-5x"></i>
        </div>
      </div>
    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%BC%98%E8%B5%B7"><span class="nav-number">1.</span> <span class="nav-text">缘起</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%85%B7%E4%BD%93%E6%AD%A5%E9%AA%A4"><span class="nav-number">2.</span> <span class="nav-text">具体步骤</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2%E5%88%B0-GitHub-Pages"><span class="nav-number">2.1.</span> <span class="nav-text">本地部署到 GitHub Pages</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#GitHub-Pages"><span class="nav-number">2.1.1.</span> <span class="nav-text">GitHub Pages</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9C%AC%E5%9C%B0-hexo"><span class="nav-number">2.1.2.</span> <span class="nav-text">本地 hexo</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%87%86%E5%A4%87%E9%83%A8%E7%BD%B2%E5%AF%86%E9%92%A5%E5%AF%B9"><span class="nav-number">2.2.</span> <span class="nav-text">准备部署密钥对</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%BA%90%E4%BB%A3%E7%A0%81%E7%A7%81%E4%BB%93-hexo"><span class="nav-number">2.3.</span> <span class="nav-text">源代码私仓 hexo</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9C%AC%E5%9C%B0%E6%BA%90%E4%BB%A3%E7%A0%81%E6%8F%90%E4%BA%A4%E5%88%B0-hexo"><span class="nav-number">2.4.</span> <span class="nav-text">本地源代码提交到 hexo</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE%E5%A5%BD%E9%83%A8%E7%BD%B2%E5%AF%86%E9%92%A5%E5%AF%B9"><span class="nav-number">2.5.</span> <span class="nav-text">配置好部署密钥对</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%A7%81%E9%92%A5%E5%88%B0-hexo"><span class="nav-number">2.5.1.</span> <span class="nav-text">私钥到 hexo</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%85%AC%E9%92%A5%E5%88%B0-haw-haw-github-io"><span class="nav-number">2.5.2.</span> <span class="nav-text">公钥到 haw-haw.github.io</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#GitHub-Actions"><span class="nav-number">2.6.</span> <span class="nav-text">GitHub Actions</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%B8%B8%E8%A7%84%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95"><span class="nav-number">3.</span> <span class="nav-text">常规使用方法</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9C%AC%E5%9C%B0%E4%BD%BF%E7%94%A8"><span class="nav-number">3.1.</span> <span class="nav-text">本地使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%9C%A8%E7%BA%BF%E4%BD%BF%E7%94%A8"><span class="nav-number">3.2.</span> <span class="nav-text">在线使用</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E8%BF%9B%E9%98%B6"><span class="nav-number">4.</span> <span class="nav-text">进阶</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%8E%A8%E8%8D%90%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95"><span class="nav-number">4.1.</span> <span class="nav-text">推荐使用方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%9A%E5%88%B6%E5%9F%9F%E5%90%8D"><span class="nav-number">4.2.</span> <span class="nav-text">定制域名</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%99%90%E5%88%B6"><span class="nav-number">4.3.</span> <span class="nav-text">限制</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">老杨</p>
  <div class="site-description" itemprop="description">好记性比不过烂笔头</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">114</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">509</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/haw-haw" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;haw-haw" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:blog@theyan.gs" title="E-Mail → mailto:blog@theyan.gs" rel="noopener me" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/u/1494877243" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;u&#x2F;1494877243" rel="noopener me" target="_blank"><i class="fab fa-weibo fa-fw"></i>Weibo</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://twitter.com/6fool" title="Twitter → https:&#x2F;&#x2F;twitter.com&#x2F;6fool" rel="noopener me" target="_blank"><i class="fab fa-twitter fa-fw"></i>Twitter</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
    <div class="sidebar-inner sidebar-blogroll">
      <div class="links-of-blogroll animated">
        <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
          链接
        </div>
        <ul class="links-of-blogroll-list">
            <li class="links-of-blogroll-item">
              <a href="https://bad-pencil.github.io/" title="https:&#x2F;&#x2F;bad-pencil.github.io" rel="noopener" target="_blank">github 镜像站</a>
            </li>
            <li class="links-of-blogroll-item">
              <a href="https://hawhaw.gitee.io/" title="https:&#x2F;&#x2F;hawhaw.gitee.io" rel="noopener" target="_blank">gitee 镜像站</a>
            </li>
        </ul>
      </div>
    </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://ming.theyan.gs/2019/10/hexo-github_action-github_pages/index.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="老杨">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="运维烂笔头">
      <meta itemprop="description" content="好记性比不过烂笔头">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="How to auto deploy Hexo site to GitHub pages via Github Actions | 运维烂笔头">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          How to auto deploy Hexo site to GitHub pages via Github Actions
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-10-02 10:41:12" itemprop="dateCreated datePublished" datetime="2019-10-02T10:41:12+08:00">2019-10-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2019-10-03 18:43:35" itemprop="dateModified" datetime="2019-10-03T18:43:35+08:00">2019-10-03</time>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><h1 id="缘起"><a href="#缘起" class="headerlink" title="缘起"></a>缘起</h1><p>业界良心的谷歌云（gcp）让我给玩儿坏了呀，原本这一期还没结束（应该到年底），可我的 300 刀的免费额度一个月前就已经花光了，于是乎，我的服务被停掉了。数据都没能机会拉取下来。</p>
<p>这样的话，给我自己折腾了进二十年的博客一个新的归宿又马上变成了火烧眉毛的事情了，早先其实一直在关注 GitHub Actions，而且也早就有申请，所以就乘着这个机会，把博客源文件、网站（静态内容）全都放在 GitHub（GitHtb Pages 服务） 上吧，同时还顺带用一下 GitHub Actions 来做自动构建、部署。</p>
<span id="more"></span>

<h1 id="具体步骤"><a href="#具体步骤" class="headerlink" title="具体步骤"></a>具体步骤</h1><h2 id="本地部署到-GitHub-Pages"><a href="#本地部署到-GitHub-Pages" class="headerlink" title="本地部署到 GitHub Pages"></a>本地部署到 GitHub Pages</h2><p>这一步要达到的目标就是：</p>
<ul>
<li>本地能写文章</li>
<li>并能 deploy 到 GitHub 上去（需要关注 hexo deploy github 这个的配置方法）</li>
<li>[username].github.io 下能访问到</li>
</ul>
<h3 id="GitHub-Pages"><a href="#GitHub-Pages" class="headerlink" title="GitHub Pages"></a>GitHub Pages</h3><ul>
<li>登录 GitHub</li>
<li>新建一个 “Repository name” 叫 [username].github.io 的 repository<ul>
<li>“[username]” 为你 GitHub 的帐号，我的例子中，叫：haw-haw.github.io</li>
<li>权限设置为：Public</li>
</ul>
</li>
</ul>
<h3 id="本地-hexo"><a href="#本地-hexo" class="headerlink" title="本地 hexo"></a>本地 hexo</h3><ul>
<li>本地需要安装配置好 nodejs、hexo、相关 theme，还有一些插件，等等，都要弄好</li>
<li>还要配置好能用 git push 东西到 GitHub 上自己的 repository 里，这步如果不会，请自行去查文档</li>
</ul>
<p>总之，要做到</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo -d </span><br></pre></td></tr></table></figure>
<p>能把</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo -g </span><br></pre></td></tr></table></figure>
<p>生成的静态内容部署到 GitHub Pages 上去</p>
<h2 id="准备部署密钥对"><a href="#准备部署密钥对" class="headerlink" title="准备部署密钥对"></a>准备部署密钥对</h2><p>本地上执行：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa -b 4096 -C <span class="string">&quot;haw-haw@users.noreply.github.com&quot;</span> -f ~/.ssh/github-actions-deploy;</span><br><span class="line"><span class="comment"># 这里的 &quot;haw-haw&quot; 替换成你自己在 GitHub 上的帐号名</span></span><br><span class="line"><span class="comment"># 执行这个命令以后，本地 ~/.ssh/ 目录下会有两个文件：github-actions-deploy 和 github-actions-deploy.pub</span></span><br><span class="line"><span class="comment"># 分别是用来 deploy 时用的公私钥密钥对。这个在后面会用到</span></span><br></pre></td></tr></table></figure>

<h2 id="源代码私仓-hexo"><a href="#源代码私仓-hexo" class="headerlink" title="源代码私仓 hexo"></a>源代码私仓 hexo</h2><p>在 GitHub 上建一个新的 repository</p>
<ul>
<li>Repository name 任取（这里假设是 hexo）</li>
<li>权限为 Private 的 repository</li>
<li>不要选中 “Initialize this repository with a README”</li>
<li>不要 Add .gitignore</li>
<li>不要 Add a license</li>
</ul>
<h2 id="本地源代码提交到-hexo"><a href="#本地源代码提交到-hexo" class="headerlink" title="本地源代码提交到 hexo"></a>本地源代码提交到 hexo</h2><ul>
<li>克隆空私仓：hexo 到本地</li>
<li>将源文件目录下的内容有选择的添加到私仓 hexo 的本地目录下<ul>
<li>public 目录不要（因为构建时会生成 public 目录下的东西）</li>
<li>node_modules 目录不要（因为在准备构建环境时会自动安装这些需要的模块的）</li>
</ul>
</li>
<li>将准备好的源代码目录内容推送到 hexo 私仓</li>
</ul>
<h2 id="配置好部署密钥对"><a href="#配置好部署密钥对" class="headerlink" title="配置好部署密钥对"></a>配置好部署密钥对</h2><h3 id="私钥到-hexo"><a href="#私钥到-hexo" class="headerlink" title="私钥到 hexo"></a>私钥到 hexo</h3><p>叫 “hexo” 的私仓建好以后，点进去，点击 Settings–&gt;Secrets–&gt;”Add a new secret”</p>
<ul>
<li>在 Name 框里填入：GH_ACTION_DEPLOY_KEY</li>
<li>在 Value 框里填入本地文件 ~&#x2F;.ssh&#x2F;github-actions-deploy 的内容（注意：是文件内容！）</li>
</ul>
<h3 id="公钥到-haw-haw-github-io"><a href="#公钥到-haw-haw-github-io" class="headerlink" title="公钥到 haw-haw.github.io"></a>公钥到 haw-haw.github.io</h3><p>进入名为 “haw-haw.github.io”(用你的用户名来取代 “haw-haw”) 的 Repository</p>
<ul>
<li>点击 Settings–&gt;”Deploy keys”–&gt;”Add deploy key”</li>
<li>Title 随意填</li>
<li>Key 框里填本地文件 ~&#x2F;.ssh&#x2F;github-actions-deploy.pub（注意：带 “.pub”） 的内容</li>
</ul>
<h2 id="GitHub-Actions"><a href="#GitHub-Actions" class="headerlink" title="GitHub Actions"></a>GitHub Actions</h2><p>在 hexo 私仓下新建文件：.github&#x2F;workflows&#x2F;hexo.yml（目录不存在的话自己建），内容如下：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">Main</span> <span class="string">workflow</span></span><br><span class="line"></span><br><span class="line"><span class="attr">on:</span></span><br><span class="line">  <span class="attr">push:</span></span><br><span class="line">    <span class="attr">branches:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="string">master</span></span><br><span class="line"></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">build:</span></span><br><span class="line"></span><br><span class="line">    <span class="attr">runs-on:</span> <span class="string">ubuntu-18.04</span></span><br><span class="line"></span><br><span class="line">    <span class="attr">steps:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">actions/checkout@v1</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Use</span> <span class="string">Node.js</span> <span class="number">10.</span><span class="string">x</span></span><br><span class="line">      <span class="attr">uses:</span> <span class="string">actions/setup-node@v1</span></span><br><span class="line">      <span class="attr">with:</span></span><br><span class="line">        <span class="attr">node-version:</span> <span class="string">&#x27;10.x&#x27;</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">prepare</span> <span class="string">build</span> <span class="string">env</span></span><br><span class="line">      <span class="attr">env:</span></span><br><span class="line">        <span class="attr">GH_ACTION_DEPLOY_KEY:</span> <span class="string">$&#123;&#123;secrets.GH_ACTION_DEPLOY_KEY&#125;&#125;</span></span><br><span class="line">        <span class="attr">NEXT_VERSION:</span> <span class="string">v7.3.0</span></span><br><span class="line">      <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">        mkdir -p ~/.ssh/</span></span><br><span class="line"><span class="string">        echo &quot;$GH_ACTION_DEPLOY_KEY&quot; | tr -d &#x27;\r&#x27; &gt; ~/.ssh/id_rsa</span></span><br><span class="line"><span class="string">        chmod 600 ~/.ssh/id_rsa</span></span><br><span class="line"><span class="string">        ssh-keyscan github.com &gt;&gt; ~/.ssh/known_hosts</span></span><br><span class="line"><span class="string">        git config --global user.name &#x27;haw-haw&#x27;</span></span><br><span class="line"><span class="string">        git config --global user.email &#x27;haw-haw@users.noreply.github.com&#x27;</span></span><br><span class="line"><span class="string">        npm i -g hexo-cli</span></span><br><span class="line"><span class="string">        npm i</span></span><br><span class="line"><span class="string"></span>    <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">deploy</span> <span class="string">to</span> <span class="string">github</span></span><br><span class="line">      <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line">        <span class="string">hexo</span> <span class="string">generate</span> <span class="string">&amp;&amp;</span> <span class="string">hexo</span> <span class="string">deploy</span></span><br></pre></td></tr></table></figure>

<p>以上就是我正在用的配置，其实基本上都是来自于 GitHub 官方的 node 的 workflow 的配置，所以具体也没什么细讲的，这里只提一个点：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">tr</span> -d <span class="string">&#x27;\r&#x27;</span> &gt; ~/.ssh/id_rsa;</span><br></pre></td></tr></table></figure>

<p>上面这一句，如果是你在部署是碰到 id_rsa 的文件格式错误的问题，那么这一句就是解决这个问题的。</p>
<h1 id="常规使用方法"><a href="#常规使用方法" class="headerlink" title="常规使用方法"></a>常规使用方法</h1><h2 id="本地使用"><a href="#本地使用" class="headerlink" title="本地使用"></a>本地使用</h2><ul>
<li>clone 私仓 hexo 到本地</li>
<li>本地在目录 source&#x2F;_posts&#x2F; 下编辑新的文件</li>
<li>提交到本地</li>
<li>push 到远端（GitHub 私仓 hexo 的 master 分支），触发构建、部署</li>
</ul>
<h2 id="在线使用"><a href="#在线使用" class="headerlink" title="在线使用"></a>在线使用</h2><p>在 web 端进入私仓 hexo 的 master 分支的 source&#x2F;_posts&#x2F; 目录下新建文件并编辑，完成后 commit，触发构建部署（这种方式不推荐，因为也许会太频繁的触发构建）</p>
<h1 id="进阶"><a href="#进阶" class="headerlink" title="进阶"></a>进阶</h1><h2 id="推荐使用方法"><a href="#推荐使用方法" class="headerlink" title="推荐使用方法"></a>推荐使用方法</h2><p>新开一个分支：draft，然后再在这个分支上做操作（修改也好、新建也好），无论是本地，还是在线，都不会触发构建（因为 GitHub Action 只在 master 下才有效），修改新建文章完毕，再 merge 到 master 分支，进而会触发 GitHub Action 自动构建、部署。</p>
<h2 id="定制域名"><a href="#定制域名" class="headerlink" title="定制域名"></a>定制域名</h2><p>如果你在 GitHub Pages 上是使用的自定义域名，而不是像我这样 haw-haw.github.io 的域名（实际上我也是自定义的域名：），那么你需要在 hexo 的 master 分支的 source&#x2F; 放一个叫 CNAME 的文件，里面写上你的自定义域名，比如我的：ming.theyan.gs。否则，每次部署，你的自定义域名配置都会被清掉！</p>
<h2 id="限制"><a href="#限制" class="headerlink" title="限制"></a>限制</h2><ul>
<li><a target="_blank" rel="noopener" href="https://github.com/features/actions">GitHub Actions</a> 目前还是 beta 状态，使用也还需要申请</li>
<li>对于私仓，GitHub Actions 超过每月 2000 分钟的时间是要收费的。<br>  我现在不到 40 篇文章，每次构建一分钟出头，如果按两分钟算，一个月可以构建 1000 次，每天可以构建 33 次，感觉怎么都够了。</li>
</ul>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wechat-reward.png" alt="老杨 微信">
        <span>微信</span>
      </div>
      <div>
        <img src="/images/alipay-reward.png" alt="老杨 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>

          <div class="followme">
  <span>欢迎关注我的其它发布渠道</span>

  <div class="social-list">

      <div class="social-item">
          <a target="_blank" class="social-link" href="https://twitter.com/6fool">
            <span class="icon">
              <i class="fab fa-twitter"></i>
            </span>

            <span class="label">Twitter</span>
          </a>
      </div>

      <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
      </div>
  </div>
</div>

          <div class="post-tags">
              <a href="/tags/Hexo/" rel="tag"># Hexo</a>
              <a href="/tags/GitHub-Actions/" rel="tag"># GitHub Actions</a>
              <a href="/tags/GitHub-Pages/" rel="tag"># GitHub Pages</a>
              <a href="/tags/nodejs/" rel="tag"># nodejs</a>
              <a href="/tags/blog/" rel="tag"># blog</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2019/09/%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE%E6%A0%87%E5%87%86%E6%8E%A8%E8%8D%90/index.html" rel="prev" title="服务器操作系统安装配置标准推荐">
                  <i class="fa fa-angle-left"></i> 服务器操作系统安装配置标准推荐
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2019/11/%E7%94%A8%20wireguard%20%E5%9C%A8%E4%B8%A4%E4%B8%AA%E7%BD%91%E7%BB%9C%E4%B9%8B%E9%97%B4%E6%89%93%E6%B4%9E/index.html" rel="next" title="用 wireguard 在两个网络之间打洞">
                  用 wireguard 在两个网络之间打洞 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">老杨</span>
  </div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>

</body>
</html>
